﻿namespace WMS6.Web.CustomizeReport
{
    using System;
    using System.Data;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.CustomizeReportServiceRef;
    using WMS6.Web.UserControls;

    public class NSNPerformanceRptList : BasePage
    {
        protected Button btnExport;
        protected Button btnList;
        protected Button btnRefresh;
        protected Button btnReSearch;
        protected Button btnSearch;
        protected HtmlForm F16031;
        protected GridView gvNSNPerformanceRptList;
        protected HtmlInputHidden hdnActionID;
        protected HtmlInputHidden hdnFrom;
        protected HtmlHead Head1;
        protected Label lblMsg;
        protected Label lblNSNPerformanceRptList;
        protected HtmlLink mycss;
        protected Pager PagerFooter;
        protected ScriptManager ScriptManager1;
        protected UpdatePanel up1;

        public void BindData2ShipmentOderRptList(NSNPerformanceReportQueryEntity nsnPerformanceReportQueryEntity)
        {
            this.PagerFooter.CurrentPage = int.Parse(nsnPerformanceReportQueryEntity.CurrentPage);
            DataSet ds = CustomizeReportServiceClientProxy.GetInstance().GetNSNPerformanceReportByDataSet(nsnPerformanceReportQueryEntity);
            base.BindData2GridView(this.gvNSNPerformanceRptList, ds);
            if ((ds != null) && (ds.Tables.Count > 1))
            {
                this.PagerFooter.PageInfo = ds.Tables[1].Rows[0]["CurrentPage"].ToString() + " / " + ds.Tables[1].Rows[0]["TotalPagesCount"].ToString() + "&nbsp;&nbsp;&nbsp;共: " + ds.Tables[1].Rows[0]["TotalRecordsCount"].ToString();
                this.PagerFooter.TotalPages = int.Parse(ds.Tables[1].Rows[0]["TotalPagesCount"].ToString());
            }
        }

        protected void btnExport_Click(object sender, EventArgs e)
        {
            NSNPerformanceReportQueryEntity nsnPerformanceReportQueryEntity = this.GetNSNPerformanceReportQueryEntity();
            nsnPerformanceReportQueryEntity.IsGetAll = true;
            this.hdnActionID.Value = "EXPORT";
            string currentPageIndex = nsnPerformanceReportQueryEntity.CurrentPage;
            nsnPerformanceReportQueryEntity.CurrentPage = "0";
            this.gvNSNPerformanceRptList.Columns[1].Visible = false;
            this.gvNSNPerformanceRptList.AllowSorting = false;
            this.BindData2ShipmentOderRptList(nsnPerformanceReportQueryEntity);
            this.gvNSNPerformanceRptList.ShowFooter = false;
            nsnPerformanceReportQueryEntity.IsGetAll = false;
            nsnPerformanceReportQueryEntity.CurrentPage = currentPageIndex;
            this.SetShipmentOrderRptQuery(nsnPerformanceReportQueryEntity);
            base.Export2Excel("NSNPerformanceReport.xls", this.gvNSNPerformanceRptList);
        }

        protected void btnFirst_Click(object sender, EventArgs e)
        {
            NSNPerformanceReportQueryEntity nsnPerformanceReportQueryEntity = this.GetNSNPerformanceReportQueryEntity();
            nsnPerformanceReportQueryEntity.CurrentPage = "0";
            this.BindData2ShipmentOderRptList(nsnPerformanceReportQueryEntity);
        }

        protected void btnLast_Click(object sender, EventArgs e)
        {
            NSNPerformanceReportQueryEntity nsnPerformanceReportQueryEntity = this.GetNSNPerformanceReportQueryEntity();
            nsnPerformanceReportQueryEntity.CurrentPage = (this.PagerFooter.TotalPages - 1).ToString();
            this.BindData2ShipmentOderRptList(nsnPerformanceReportQueryEntity);
        }

        protected void btnList_Click(object sender, EventArgs e)
        {
            NSNPerformanceReportQueryEntity nsnPerformanceReportQueryEntity = this.GetNSNPerformanceReportQueryEntity();
            nsnPerformanceReportQueryEntity.RECEIPT_ID = "";
            nsnPerformanceReportQueryEntity.VENDOR_CITY = "";
            nsnPerformanceReportQueryEntity.VENDOR_NAME = "";
            nsnPerformanceReportQueryEntity.SKU_ID = "";
            nsnPerformanceReportQueryEntity.EXTERNAL_LOT = "";
            nsnPerformanceReportQueryEntity.CREATED_DATE = "";
            nsnPerformanceReportQueryEntity.UDF10 = "";
            nsnPerformanceReportQueryEntity.LOT_ATTR01 = "";
            nsnPerformanceReportQueryEntity.START_DATETIME = "";
            nsnPerformanceReportQueryEntity.END_DATETIME = "";
            this.BindData2ShipmentOderRptList(nsnPerformanceReportQueryEntity);
        }

        protected void btnNext_Click(object sender, EventArgs e)
        {
            NSNPerformanceReportQueryEntity nsnPerformanceReportQueryEntity = this.GetNSNPerformanceReportQueryEntity();
            if (int.Parse(nsnPerformanceReportQueryEntity.CurrentPage) < (this.PagerFooter.TotalPages - 1))
            {
                nsnPerformanceReportQueryEntity.CurrentPage = (int.Parse(nsnPerformanceReportQueryEntity.CurrentPage) + 1).ToString();
                this.BindData2ShipmentOderRptList(nsnPerformanceReportQueryEntity);
            }
        }

        protected void btnPrevious_Click(object sender, EventArgs e)
        {
            NSNPerformanceReportQueryEntity nsnPerformanceReportQueryEntity = this.GetNSNPerformanceReportQueryEntity();
            if (int.Parse(nsnPerformanceReportQueryEntity.CurrentPage) > 0)
            {
                nsnPerformanceReportQueryEntity.CurrentPage = (int.Parse(nsnPerformanceReportQueryEntity.CurrentPage) - 1).ToString();
                this.BindData2ShipmentOderRptList(nsnPerformanceReportQueryEntity);
            }
        }

        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            NSNPerformanceReportQueryEntity nsnPerformanceReportQueryEntity = this.GetNSNPerformanceReportQueryEntity();
            this.BindData2ShipmentOderRptList(nsnPerformanceReportQueryEntity);
        }

        private NSNPerformanceReportQueryEntity GetNSNPerformanceReportQueryEntity()
        {
            return (base.PageQueryEntitySession as NSNPerformanceReportQueryEntity);
        }

        protected void GoTo_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(((TextBox) this.PagerFooter.FindControl("txtGo2Page")).Text.Trim()))
            {
                NSNPerformanceReportQueryEntity nsnPerformanceReportQueryEntity = this.GetNSNPerformanceReportQueryEntity();
                nsnPerformanceReportQueryEntity.CurrentPage = this.PagerFooter.GoToPage.ToString();
                this.BindData2ShipmentOderRptList(nsnPerformanceReportQueryEntity);
            }
        }

        protected void gvNSNPerformanceRptList_Init(object sender, EventArgs e)
        {
            base.InitDetailGridView("F16031", this.gvNSNPerformanceRptList);
        }

        protected void gvNSNPerformanceRptList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].Text = (((this.PagerFooter.CurrentPage * this.PagerFooter.PageSize) + e.Row.RowIndex) + 1).ToString();
                e.Row.Attributes.Add("onmouseout", "GridViewRowMouseout(this);");
                e.Row.Attributes.Add("onmouseover", "GridViewRowMouseover(this);");
                if (this.hdnActionID.Value != "EXPORT")
                {
                    base.SetGridViewLongTextLabel((Label) e.Row.FindControl("lblSkuDescr"));
                }
                decimal str1 = 0M;
                decimal str2 = 0M;
                if (!string.IsNullOrEmpty(((Label) e.Row.FindControl("lblMHour")).Text))
                {
                    str1 = Convert.ToDecimal(((Label) e.Row.FindControl("lblMHour")).Text);
                }
                if (!string.IsNullOrEmpty(((Label) e.Row.FindControl("lblUf1")).Text))
                {
                    str2 = Convert.ToDecimal(((Label) e.Row.FindControl("lblUf1")).Text);
                }
                if (str1 <= str2)
                {
                    ((Label) e.Row.FindControl("lblIsTime")).Text = "否";
                }
                else
                {
                    ((Label) e.Row.FindControl("lblIsTime")).Text = "是";
                }
            }
        }

        protected void gvNSNPerformanceRptList_Sorting(object sender, GridViewSortEventArgs e)
        {
            try
            {
                NSNPerformanceReportQueryEntity nsnPerformanceReportQueryEntity = this.GetNSNPerformanceReportQueryEntity();
                nsnPerformanceReportQueryEntity.SortField = e.SortExpression;
                if (nsnPerformanceReportQueryEntity.SortDirection == "ASC")
                {
                    nsnPerformanceReportQueryEntity.SortDirection = "DESC";
                }
                else if (nsnPerformanceReportQueryEntity.SortDirection == "DESC")
                {
                    nsnPerformanceReportQueryEntity.SortDirection = "ASC";
                }
                this.BindData2ShipmentOderRptList(nsnPerformanceReportQueryEntity);
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }

        private void LoadData()
        {
            NSNPerformanceReportQueryEntity nsnPerformanceReportQueryEntity = new NSNPerformanceReportQueryEntity();
            if (string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                if (this.PreviousPage != null)
                {
                    nsnPerformanceReportQueryEntity.RECEIPT_ID = this.PreviousPage.ReceiptID;
                    nsnPerformanceReportQueryEntity.VENDOR_CITY = this.PreviousPage.VendorCity;
                    nsnPerformanceReportQueryEntity.VENDOR_NAME = this.PreviousPage.VendorName;
                    nsnPerformanceReportQueryEntity.SKU_ID = this.PreviousPage.SkuID;
                    nsnPerformanceReportQueryEntity.EXTERNAL_LOT = this.PreviousPage.ExtrernalLot;
                    nsnPerformanceReportQueryEntity.CREATED_DATE = this.PreviousPage.CreatedDate;
                    nsnPerformanceReportQueryEntity.UDF10 = this.PreviousPage.UDF10;
                    nsnPerformanceReportQueryEntity.LOT_ATTR01 = this.PreviousPage.LotAttr01;
                    nsnPerformanceReportQueryEntity.START_DATETIME = this.PreviousPage.StartTime;
                    nsnPerformanceReportQueryEntity.END_DATETIME = this.PreviousPage.EndTime;
                }
                else
                {
                    nsnPerformanceReportQueryEntity.RECEIPT_ID = "";
                    nsnPerformanceReportQueryEntity.VENDOR_CITY = "";
                    nsnPerformanceReportQueryEntity.VENDOR_NAME = "";
                    nsnPerformanceReportQueryEntity.SKU_ID = "";
                    nsnPerformanceReportQueryEntity.EXTERNAL_LOT = "";
                    nsnPerformanceReportQueryEntity.CREATED_DATE = "";
                    nsnPerformanceReportQueryEntity.UDF10 = "";
                    nsnPerformanceReportQueryEntity.LOT_ATTR01 = "";
                    nsnPerformanceReportQueryEntity.START_DATETIME = "";
                    nsnPerformanceReportQueryEntity.END_DATETIME = "";
                }
            }
            else
            {
                this.hdnFrom.Value = base.Request.QueryString["from"].ToString();
            }
            nsnPerformanceReportQueryEntity.IsGetAll = false;
            nsnPerformanceReportQueryEntity.CurrentPage = "0";
            nsnPerformanceReportQueryEntity.PageSize = this.gvNSNPerformanceRptList.PageSize.ToString();
            nsnPerformanceReportQueryEntity.SortField = "RECEIVED_DATE";
            nsnPerformanceReportQueryEntity.SortDirection = "ASC";
            this.PagerFooter.PageSize = this.gvNSNPerformanceRptList.PageSize;
            this.SetShipmentOrderRptQuery(nsnPerformanceReportQueryEntity);
            this.BindData2ShipmentOderRptList(nsnPerformanceReportQueryEntity);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
            }
        }

        public void SetShipmentOrderRptQuery(NSNPerformanceReportQueryEntity nsnPerformanceReportQueryEntity)
        {
            base.PageQueryEntitySession = nsnPerformanceReportQueryEntity;
        }

        public NSNPerformanceRptQuery PreviousPage
        {
            get
            {
                return (NSNPerformanceRptQuery) base.PreviousPage;
            }
        }
    }
}

